/* 
 * File:   Character.h
 * Author: paula
 *
 * Created on 8 de septiembre de 2014, 23:26
 */

#ifndef CHARACTER_H
#define	CHARACTER_H


#include "../Define/DefaultValues.h"
#include <string>
#include "Object.h"
#include "WorldElement.h"
#include "ObjFactory.h"
#include "Dot.h"
#include <chrono>
#include "SnowBall.h"
#include "SnowGun.h"
using namespace std;

class Character : public WorldElement {
public:

    Character();
    Character(ObjFactory *objFactory, int x, int y, int id);
    Character(const Character& orig);
    bool equals;
    void wait();
    void walkRight();
    void walkLeft();
    //    void walkRight(float velocityX);
    //    void walkLeft(float velocityX);
    void jump();
    void kneel();
    void die(); // muerte para desconexion
    void kill(); // muerte para lifes== 0

    bool isJumping();
    bool isKneeling();
    bool isFallingDown();
    bool isWalking();
    bool isWalkingRight();
    bool isWalkingLeft();
    bool isWatching();

    void keepJumping();
    void keepKneeling();
    void keepFallingDown();
    void keepWalking();

    void fallRight();
    void fallLeft();
    void jumpingRight();
    void jumpingLeft();
    void stopWalking();
    void stopKneeling();

    int getState();
    float getPosX();
    float getPosY();
    float getPosInitialX();
    float getPosInitialY();

    struct ObjectInit getData();
    int getUbicDyn();
    b2Body* getBody();
    bool getAreEquals();
    int getScore();
    int getLifes();

    void setCharacterId(int i);
    void setUbicDyn(int i);

    void updateData();
    void updateEvent(struct Event e);

    void checkChanges();
    void changeToPosInitial();

    bool isInContactBonus();
    bool isInContactEnemy();
    bool isInContactSnowBallEnemy();
    bool isInContactCrazyBall();

    void walkFaster();

    void restartPlayer();
    //shoot
    SnowBall* shoot();
    
    void setWaiting();
    
    virtual ~Character();

protected:

    struct ObjectInit data;
    Dot *dot;

    bool directionRight;
    bool wasJumping;
    bool beginning;
    bool jumping, kneeling, fallingDown, walking, dead, dying;
    bool watching;
    int counterKneel, counterJump, counterWait;
    int delayWalk, delay;
    float windowPixelWidth, windowPixelHeight, windowUnitWidth, windowUnitHeight;
    float lastPosY, currentPosY, lastVelY, currentVelY;

    int lastState;

    float objWidth, objHeight;
    Object* object;
    ObjFactory *objFactory;
    SBSLog* myLogFile;

    float velocityWalkLeft;
    float velocityWalkRight;

    float posX;
    float posY;
    b2Vec2 posInitial;
    int score;
    int lifes;

    void jumpRight();
    void jumpLeft();
    void moveRight(float velocityX, float velocityY);
    void moveLeft(float velocityX, float velocityY);
    void actualizePosition();

    void updatePosition();
    void updateState();
    void updateRotation();

    SnowGun *weapon;

    float maxVelocity;
    float deltaVelocity;
    
    bool canJumpRight, canJumpLeft, canFallRight, canFallLeft;
    void resetFallingAndJumping();

private:

    bool walkingFaster;

    bool trapped;
    float maxVelocityStandard;
    float maxVelocityPlus;
    int plusVelTime; //seconds



    float constFall, constJump;

    int counterReborn;

    b2Body* crazyBallKidnapper;

    std::chrono::time_point<std::chrono::system_clock> startPlusVel;
    std::chrono::time_point<std::chrono::system_clock> nowVel;

    bool characterOverlap(int x, int y);
    void changePosition(float x, float y);
    //    int nd;
    
    bool avisarleATodos;
    int contAvisarleATodos;
        
    void notBeInvisible();
};

#endif	/* CHARACTER_H */
